////////////////////////////////////////
// Autor:Mato Prorams 2010            //
// (C) Mato Programs 2010             //
////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MBMC.Paths;

namespace MBMC.Dialogs
{
    public partial class IntermediateMissions : Form
    {
        string mbfolder;
        Paths.Paths p = new MBMC.Paths.Paths();
        public IntermediateMissions(string actualmbfolder)
        {
            InitializeComponent();
            mbfolder = actualmbfolder;
        }

        private void BegginerMissions_Load(object sender, EventArgs e)
        {
            System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(p.Vrat_Cestu(mbfolder, MBPaths.FMDMIntermediateMisions));
            foreach (System.IO.FileInfo file in di.GetFiles("*.mis"))
            {
                Console.WriteLine("{0}, {1}, {2}", file.Name, file.Length, file.Extension);
                listBox1.Items.Add(file.Name);
            }
            foreach (System.IO.FileInfo file in di.GetFiles("*.jpg"))
            {
                Console.WriteLine("{0}, {1}, {2}", file.Name, file.Length, file.Extension);
                listBox2.Items.Add(file.Name);
            }
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            listBox2.SelectedIndex = listBox1.SelectedIndex;
            filename.Text = listBox1.SelectedItem.ToString();
            pictureBox1.ImageLocation = p.Vrat_Cestu(mbfolder, MBPaths.FMDMIntermediateMisions) + "/" + listBox2.SelectedItem.ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            PrimitiveEditor pe = new PrimitiveEditor(p.Vrat_Cestu(mbfolder, MBPaths.FMDMIntermediateMisions) + "/" + listBox1.SelectedItem.ToString());
            pe.ShowDialog();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
        }

        private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
        {
            System.IO.FileInfo fi = new System.IO.FileInfo(openFileDialog1.FileName);

            fi.CopyTo(p.Vrat_Cestu(mbfolder, MBPaths.FMDMIntermediateMisions) + "/" + fi.Name);

            MessageBox.Show("You must choose mission preview! for fully functionaly of MBMC", "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);

            //openFileDialog2.Filter = 

            openFileDialog2.ShowDialog();

            DialogResult dr = MessageBox.Show("Click on OK!", "Mato Programs", MessageBoxButtons.OK, MessageBoxIcon.None);
            if (dr == DialogResult.OK)
            {
                //try
                //{

                System.IO.FileInfo fip = new System.IO.FileInfo(openFileDialog2.FileName);
                //if (fip.Extension = ".jpg")
                //{
                ///////PRIPAD JPG
                fip.CopyTo(p.Vrat_Cestu(mbfolder, MBPaths.FMDMIntermediateMisions) + "/" + fip.Name);
                //}
                //else
                //{
                //////PRIPAD PNG
                //////PREMENOVAT FILE.PNG NA FILE.JPG
                //MessageBox.Show("Not avaiable :( \nWork in progress!");
                //}
                //}
                //catch
                //{
                /*MessageBox.Show("Now is used as a level preview default image");
                System.IO.FileInfo fii = new System.IO.FileInfo(Application.StartupPath + "\\data\\img\\basimp.jpg");

                fii.CopyTo(p.Vrat_Cestu(mbfolder, MBPaths.FMDMIntermediateMisions) + "\\" + openFileDialog1.FileName);
                 */
                //}
            }
            else
            {
                /*
                //try
                //{
                    System.IO.FileInfo fiii = new System.IO.FileInfo(Application.StartupPath + "/data/img/basicmp.jpg");

                    fiii.CopyTo(p.Vrat_Cestu(mbfolder, MBPaths.FMDMIntermediateMisions) + "/" + openFileDialog1.FileName);
                //}
                /*catch
                {
                    MessageBox.Show("Error in this application download latest version from www.mbmc.codeplex.com, if error show always, please send your feedback on the MBMC MainMenu>Web>Send Feedback, and i improve your problem.");
                }*/
            }

            MessageBox.Show("This dialog must be restarted to show new information");
            this.Close();
            //this.ShowDialog();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            System.IO.FileInfo fi = new System.IO.FileInfo(p.Vrat_Cestu(mbfolder, MBPaths.FMDMIntermediateMisions) + "/" + listBox1.SelectedItem.ToString());

            fi.Delete();

            System.IO.FileInfo fit = new System.IO.FileInfo(p.Vrat_Cestu(mbfolder, MBPaths.FMDMIntermediateMisions) + "/" + listBox2.SelectedItem.ToString());

            fit.Delete();
            MessageBox.Show("This dialog must be restarted to show new information");
            this.Close();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
        }

        private void openFileDialog2_FileOk(object sender, CancelEventArgs e)
        {
//none
        }

        private void button2_Click(object sender, EventArgs e)
        {
            MessageBox.Show("To start the game, go to main MBMC screen a then click on Game menuitem and click on Play menuitem.");
        }
    }
}